package com.myz.springboot2.xml;

import com.alibaba.fastjson.JSON;
import com.myz.springboot2.xml.domain.BaseField;
import com.myz.springboot2.xml.domain.Folder;
import com.myz.springboot2.xml.domain.FolderWrapper;
import com.myz.springboot2.xml.utils.BeanCopyUtils;
import com.myz.springboot2.xml.utils.JaxbUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.File;
import java.util.List;

@SpringBootApplication
@Slf4j
public class Springboot2XmlApplication {
    public static void main(String[] args) {
        SpringApplication.run(Springboot2XmlApplication.class, args);
        FolderWrapper folder = JaxbUtil.toBean(new File("D:\\桌面\\案卷打包检测\\eepPath\\pde-GL•01•2023•Y-001\\目录文件.xml"), FolderWrapper.class);
        System.out.println(folder);
        System.out.println(JSON.toJSONString(folder));

        String xml = JaxbUtil.toXml(folder);
        System.out.println(xml);

        Folder folder1 = folder.getRecords().get(0);
        List<BaseField> children = folder1.getChildren();
        for (BaseField child : children) {
            // 先清空
            FolderWrapper folderCopy = new FolderWrapper();
            Folder folderTemp = BeanCopyUtils.deepCopy(folder1);
            folderCopy.getRecords().add(folderTemp);
            folderTemp.getChildren().clear();
            folderTemp.getChildren().add(child);


            String xml1 = JaxbUtil.toXml(folderCopy);
            System.out.println(xml1);
        }
        System.out.println(JaxbUtil.toXml(folder));
    }
}
